/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cf.dao.impl;

import com.cf.bean.TbPalabraBean;
import com.cf.modelo.EjercicioBean;
import com.cf.modelo.TbPalabra;
import com.cf.util.HibernateUtil;
import java.awt.Image;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Soltecn2
 */
@Service
@Transactional
public class TbPalabraDao {

    public static List<TbPalabra> listPalabras(String b) {
        List<TbPalabra> lst = new ArrayList<TbPalabra>();




        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            if (b == null) {
            }
            String sqlquery = "from TbPalabra where descripcion LIKE :desc";
            lst = session.createQuery(sqlquery).setString("desc", "%" + b + "%").list();


        } catch (Exception e) {
            e.getMessage();
        }
        return lst;
    }

    public int actualizar1(String imgA, String imgB, int cod, int cod_ejer, String enlace,int codigotmp) {
        int resultado = 0;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Connection connection = session.connection();

            String sql = "{ CALL entrenamiento.update_tmp_ejerciciocf('" + imgA + "','"+enlace+"',"+cod+","+cod_ejer+","+codigotmp+")}";
            CallableStatement prepareCall = connection.prepareCall(sql);
            prepareCall.execute();
            prepareCall.close();
            session.getTransaction().commit();
        } catch (Exception e) {
            System.out.println("Error al eliminar: " + e.getMessage());
        }
        return resultado;
    }

    public int actualizar2(String imgA, String imgB, int cod, int cod_ejer,int codigotmp) {
         int resultado = 0;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Connection connection = session.connection();

            String sql = "{ CALL entrenamiento.update_tmp_ejerciciocf2('" + imgB + "',"+cod+","+cod_ejer+","+codigotmp+")}";
            CallableStatement prepareCall = connection.prepareCall(sql);
            prepareCall.execute();
            prepareCall.close();
            session.getTransaction().commit();
        } catch (Exception e) {
            System.out.println("Error al eliminar: " + e.getMessage());
        }
        return resultado;


    }

    public int eliminar2(int codEjer) {
        int resultado = 0;

        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            Connection connection = session.connection();

            String sql = "{ CALL entrenamiento.SP_DELETE_DETALLE(" + codEjer + ")}";
            CallableStatement prepareCall = connection.prepareCall(sql);
            prepareCall.execute();
            prepareCall.close();
            session.getTransaction().commit();





        } catch (Exception e) {
            System.out.println("Error al eliminar: " + e.getMessage());
        }
        return resultado;
    }
}
